package client;

import java.io.IOException;

public class ClientReadThread extends Thread {
	 private Client client;
	 
	 public ClientReadThread(Client client)
	 {
			this.client = client;
	 }
	 
	 public int dealWithMsg(String request)
     {//TODO
		 if(request.startsWith("newGroup"))
       		client.doNewGroup(request);
         else if(request.startsWith("delGroup"))
   		    client.doDelGroup(request);
         else if(request.startsWith("beHelp"))
      		client.doBeHelp(request);
      	else if(request.startsWith("beFred"))
             client.dobeFred(request);
        else if(request.startsWith("chat"))
            client.doChat(request);
      	else if(request.startsWith("Act"))
      		client.doAct(request);
      	else if(request.startsWith("Gchat"))
      		client.doGchat(request);
      	else if(request.startsWith("FredLogOn"))
      		client.doFredLogOn(request);
      	else if(request.startsWith("FredLogOff"))
      		client.doFredLogOff(request);
      	else if(request.startsWith("FredCheckIN"))
      		client.doFredCheckIN(request);
    	else if(request.startsWith("FredCheckOFF"))
      		client.doFredCheckOFF(request);
      	else if(request.startsWith("GroupMemLogOff"))
      		client.doGroupMemLogOff(request);
      	else if(request.startsWith("GroupMemLogOn"))
      		client.doGroupMemLogOn(request);
      	else
      	{
      		return -1;
      	}
      	return 0;
      }
     
	 public void run()
	 {
			String msgReceived = "";
			try
			{
				while (true)
				{ // 等待信息输入
					msgReceived = client.in2.readLine();
					if(msgReceived!=null)
					{
					 dealWithMsg(msgReceived);
					 System.out.println("服务端说：  "+msgReceived );
					 sleep(2);
					 msgReceived=null;
					}
				}
			}
			catch (IOException e1){
				e1.printStackTrace();
			} 
			catch (InterruptedException e2) {
				e2.printStackTrace();
			}
	}
	 
	 
}
